
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';



class MyTest extends StatelessWidget{


  @override
  Widget build(BuildContext context) {
    // TODO: implement build

    return new MaterialApp(

      title: "测试",
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text("页面交互"),
        ),
        body: new MyTestJava(),
      ),
    );
  }

}

class MyTestJava extends StatefulWidget{


  @override
  MyTestJavaState createState() {
    // TODO: implement createState
    return new MyTestJavaState("init");
  }

}

class MyTestJavaState extends  State<MyTestJava> {

  static const platform = const MethodChannel('samples.flutter.io/battery');
  String text;


  MyTestJavaState(this.text);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Center(
        child: new Column(
          children: <Widget>[
            _getNewData(),
            new MaterialButton(onPressed: _getBatteryLevel,
            child: new Text("这是个测试的"),
            )
          ],
        ),
    );
  }

  Text _getNewData() {
    return new Text(text);
  }


  void _getBatteryLevel() async {
    String newTest;
    print("触发点击事件");
    try {
      final String result = await platform.invokeMethod('getBatteryLevel');
      newTest = 'new Message: $result';
    } on Exception catch (e) {
      newTest='error:${e.toString()}';
    }
    print("打印结果：$newTest");
    setState(() {
      text=newTest;
    });
  }
}